#! /bin/sh

if [ "$#" -lt 2 ]; then
    echo "not enought args"
    exit 1
fi

if ! hash docker-compose 2>/dev/null;then
    echo "can't find docker-compose"
    exit 1
fi


Set() {
    guid=$1
    nats=$2

    sed -i -e "s/{AGENT_GUID}/${guid}/g"  -e "s@{NATS_ADDR}@${nats}@g" `grep -rl -E "NATS_ADDR|AGENT_GUID" $root_dir`
    docker-compose -f $root_dir/docker-compose.yaml up -d
}

Clear() {
    docker-compose -f $root_dir/docker-compose.yaml down
}

action=$1
target=$2
root_dir=`(cd $(dirname $0);pwd)`/$target

if [ "$action" = "set" ];then

if [ "$#" -lt 3 ]; then
    echo "not enought args"
    exit 1
fi

Set $3 $4

else
Clear
fi








